from typing import List
from unittest import result
from rikapycli.tkTerminal import TkTerminal
from rikapycli import *


class SubCommand(CommandManager):
    def CMD_hello(self, args: List[str]) -> Result:
        return Result(message="Hello！！！")


class MainCommand(CommandManager):
    def __init__(self) -> None:
        super().__init__()
        self.add_sub_command(SubCommand(), 'sub')

    def CMD_test(self, args: List[str]) -> Result:
        """
        测试指令是否正常
        """
        return Result(message="你输入了：" + ', '.join(args), result=args.copy())

    def CMD_dirs(self, args: List[str]) -> Result:
        """
        获取当前目录下的全部内容
        """
        import os
        return Result(message="\n".join(os.listdir()))

    def CMD_call(self, args: List[str]) -> Result:
        al = len(args)
        if al == 0:
            return Result(message="准备call什么？", code=-1)
        if al == 1:
            exec(args[0] + "()")
            return Result(message="Ok")
        exec(args[0] + "(" + ",".join(args[1:]) + ")")
        return Result(message='Ok')


tk = TkTerminal(Commander(MainCommand()))

tk.show()
